package com.example.zhangxin.myhuatuob2b.bean;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

/**
 * Created by ZhangXin on 2016/10/12.
 */

public class OneType {
    public static final String GC_ID = "gc_id";
    public static final String GC_NAME = "gc_name";
    public static final String IMAGE = "image";
    public static final String TEXT = "text";

    private String gc_id;
    private String gc_name;
    private String image;
    private String text;

    public OneType(String gc_id, String gc_name, String image, String text) {
        this.gc_id = gc_id;
        this.gc_name = gc_name;
        this.image = image;
        this.text = text;
    }

    public OneType() {

    }

    public static ArrayList<OneType> newInstanceList(String json){
        ArrayList<OneType> data = new ArrayList<>();
        try {
            JSONArray array = new JSONArray(json);
            int size = null == array ? 0 : array.length();
            for (int i = 0; i < size; i++) {
                JSONObject object = array.getJSONObject(i);
                String id = object.optString(GC_ID);
                String name = object.optString(GC_NAME);
                String image = object.optString(IMAGE);
                String text = object.optString(TEXT);
                data.add(new OneType(id,name,image,text));
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return data;
    }

    public String getGc_id() {
        return gc_id;
    }

    public void setGc_id(String gc_id) {
        this.gc_id = gc_id;
    }

    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }

    public String getGc_name() {
        return gc_name;
    }

    public void setGc_name(String gc_name) {
        this.gc_name = gc_name;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }
}
